<template>
    <view>
        <u-navbar title="我的回复" :background="background" back-icon-color="#efefef" title-color="#efefef"></u-navbar>
        <view class="wrap">
            <view v-for="item in commentList" :key="item.id">
                <view class="comment">
                <view  @click="goToOne(item.type,item.articleId)" class="left">
                    <view class="main">
                        <u-parse :html="item.content"></u-parse>
                    </view>
                    <view class="time">{{item.createTime}}</view>
                    
                </view>
                <view class="right" @click="deleteComment(item.id)">
                    <u-icon label="删除" label-color="#626768" label-size="24" size="30" name="/static/icon/delete.png"></u-icon>
                </view>
                
                <u-line color="black" />
                </view>
            </view>
        </view>
    </view>
    </view>
</template>

<script>
    import {
        selectMyForums,
        getMyComments,
        deleteComments,
    } from "@/api/data.js"
    export default {

        data() {
            return {
                background: {
                    backgroundImage: 'linear-gradient(45deg, rgb(255, 40, 0), rgb(147, 0, 0))'

                },
                commentList: [],
                myId: 0,
            }
        },
        onLoad(options) {
            this.myId = options.userId
        },
        onShow() {
            // if(this.myId!=0)
            this.getMyComments()
        },
        methods: {
            goToOne(type, id) {
                if (type == 0) {
                    uni.navigateTo({
                        url: '/pages/forum/main/index?id=' + id
                    })
                } else {
                    uni.navigateTo({
                        url: '/pages/articles/index?id=' + id + '&type=' + type,
                    });
                }


            },
            getMyComments() {
                const _this = this
                // console.log("hellp")
                getMyComments({
                    userId: this.myId
                }).then(function(res) {
                    // console.log(res.data.data)
                    _this.commentList = res.data.data
                })
            },
            deleteComment(id){
                const _this=this
                uni.showModal({
                    title: '提示',
                    content: '确定删除该条评论！',
                    success: function(res) {
                        if (res.confirm) {
                            // console.log('用户点击确定');
                            deleteComments({
                                id: id
                            }).then(function(res){
                                _this.getMyComments()
                            })
                            
                
                        } else if (res.cancel) {
                            console.log('用户点击取消');
                            
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
    .wrap {
        display: flex;
        flex-direction: column;
        // height: 100vh;
        min-height: calc(100vh - var(--window-top));
        width: 100%;
        background-color: #ffffff;
        // margin-top: 80rpx;
        // background-color: #fff9ee;
    }

    .comment {
        padding: 10rpx 30rpx;

        // height: 100rpx;
        .main {
            padding: 20rpx 0;
        }

        .time {
            font-size: 25rpx;
            color: #808080;
            padding: 5rpx 0;
        }
    }
    .left {
        display: inline-block;
    }
    .right{
        display: inline-block;
        float: right;
        padding: 20rpx;
        margin:auto;
     // padding: 10rpx 20rpx;
     }
    
</style>
